package com.busi.ecTemplate.service;

import java.io.File;
import java.util.Date;

import com.busi.ecTemplateItem.entity.TemplateItem;
import com.jfinal.upload.UploadFile;
import com.zcurd.common.util.DateUtil;
import com.zcurd.common.util.StringUtil;

public class TemplateService {

	public void uploadFile(UploadFile file, TemplateItem model, long id) {
		String fileName = file.getFileName();
		int index = fileName.lastIndexOf(".");
		String fileType = fileName.substring(index + 1);
		String saveName = DateUtil.dateToString(new Date(), "yyyyMMddHHmmss") + StringUtil.randomNumber() + "."
				+ fileType;
		String newFilePath = file.getUploadPath() + "\\" + saveName;
		File delfile = new File(newFilePath);
		file.getFile().renameTo(delfile);
		model.setTemplateId(id);
		model.setTemplateItemName(fileName);
		model.setTemplateItemPath(delfile.getPath());
		model.setTemplateItemType(fileType);
		model.save();
		System.out.println("----------------上传文件路径：" + delfile.getPath());
	}
}
